package org.springframework.amqp.tutorials.rabbitmq_topics;

import org.springframework.amqp.tutorials.rabbitmq_topics.runner.TopicsCommandLineRunner;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.EnableScheduling;

@EnableScheduling
@SpringBootApplication
public class RabbitmqTopicsApplication {

    public static void main(String[] args) {
        SpringApplication.run(RabbitmqTopicsApplication.class, args);
    }

    @Profile("usage_message")
    @Bean
    public CommandLineRunner usage() {
        return args -> {
            System.out.println("This app uses Spring Profile to control its behavior");
            System.out.println("Sampling usage:");
            System.out.println("java -jar rabbitmq_topics-0.0.1.jar" +
                    " --spring.profiles.active=topics,sender");
            System.out.println("java -jar rabbitmq_topics-0.0.1.jar" +
                    " --spring.profiles.active=topics,receiver");
        };
    }

    @Profile("!usage_message")
    @Bean
    public TopicsCommandLineRunner topics() {
        return new TopicsCommandLineRunner();
    }
}
